//
//  setDetailShowViewControl.swift
//  智慧魔盒
//
//  Created by 梓简王 on 2017/4/10.
//  Copyright © 2017年 DW. All rights reserved.
//

import Foundation
import JSQWebViewController

class setDetailShowViewControl:UIViewController,headerViewDelegate{
    private final var activities: [UIActivity]?
    var vcNav:UINavigationBar?
    var header:headerView?
    var headerImage:UIImageView?
    var mainScroView:UIScrollView?
    var contentView:UIView?
    var contentViewHeight:CGFloat?
    var contentViewWeight:CGFloat?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = commonVariable.BACKGROUNDCOLOR
        createHeader()
        createScroView()
        addContactLink()
    }
    //添加联系方式
    func addContactLink(){
        let sinaButton = UIButton(frame: CGRectMake(0, 66, 44, 44))
        sinaButton.center = CGPoint(x: 50,y: commonVariable.SYSTEM_HEIGHT - 45)
        sinaButton.setBackgroundImage(UIImage(named: "xn_share_sina"), forState: UIControlState.Normal)
        let HostButton = UIButton(frame: CGRectMake(0, 66, 44, 44))
        HostButton.center = CGPoint(x: commonVariable.SYSTEM_WIDTH - 50,y: commonVariable.SYSTEM_HEIGHT - 45)
        HostButton.setBackgroundImage(UIImage(named: "xn_share_wx1"), forState: UIControlState.Normal)
        sinaButton.addTarget(self, action: "clickSinaBtn", forControlEvents: UIControlEvents.TouchUpInside)
        HostButton.addTarget(self, action: "clickHostBtn", forControlEvents: UIControlEvents.TouchUpInside)
        self.view.addSubview(sinaButton)
        self.view.addSubview(HostButton)
    }
    //新浪响应
    func clickSinaBtn(){
        let webVC = WebViewController(url: NSURL(string: "http://weibo.com/1746639594/profile?topnav=1&wvr=6&is_all=1")!)
        //下面被注释的可以push进去
        //navigationController?.pushViewController(webVC, animated: true)
        let nav = UINavigationController(rootViewController: webVC)
        presentViewController(nav, animated: true, completion: nil)
    }
    //主页响应
    func clickHostBtn(){
        let webVC = WebViewController(url: NSURL(string: "http://blog.dpgeek.cn/geekBlog/articles/2017/02/27/1488179338703.html")!)
        //下面被注释的可以push进去
        //navigationController?.pushViewController(webVC, animated: true)
        let nav = UINavigationController(rootViewController: webVC)
        presentViewController(nav, animated: true, completion: nil)
    }
    //添加详细信息
    func createScroView(){
        self.mainScroView = UIScrollView(frame: CGRectMake(0, 66, commonVariable.SYSTEM_WIDTH, commonVariable.SYSTEM_HEIGHT - 66))
        mainScroView!.backgroundColor = commonVariable.BACKGROUNDCOLOR
        // 自适应父视图
        mainScroView!.autoresizingMask = UIViewAutoresizing.FlexibleHeight
        // 其他属性
        mainScroView!.scrollEnabled = true // 可以上下滚动
        mainScroView!.scrollsToTop = true // 点击状态栏时，可以滚动回顶端
        mainScroView!.bounces = true // 反弹效果，即在最顶端或最底端时，仍然可以滚动，且释放后有动画返回效果
        mainScroView!.pagingEnabled = false // 分页显示效果
        mainScroView!.showsHorizontalScrollIndicator = false // 显示水平滚动条
        mainScroView!.showsVerticalScrollIndicator = false // 显示垂直滚动条
        // 设置内容大小
        mainScroView!.contentSize = CGSizeMake(CGRectGetWidth(self.view.bounds), contentViewHeight! + 120)
        
        if(headerImage != nil){
            self.headerImage?.contentMode = UIViewContentMode.ScaleAspectFill
            self.headerImage?.layer.masksToBounds = true
            self.headerImage?.layer.cornerRadius = 35
            self.headerImage?.center = CGPoint(x: commonVariable.SYSTEM_WIDTH/2, y: 50)
            self.mainScroView?.addSubview(self.headerImage!)
            self.contentView?.frame = CGRectMake((commonVariable.SYSTEM_WIDTH - self.contentViewWeight!)/2, 120, self.contentViewWeight!, self.contentViewHeight!)
            self.mainScroView?.addSubview(self.contentView!)
        }else{
            self.contentView?.frame = CGRectMake(0, 66, self.contentViewWeight!, self.contentViewHeight!)
            self.mainScroView?.addSubview(self.contentView!)
        }
        self.view.addSubview(self.mainScroView!)
    }
    
    func rightClick(sender:UIButton){
        //分享响应事件
        //亲,收快递不在家怎么办？快递到了没通知怎么办？这几天都在外地怎么办？智慧魔盒统统搞定~ 
        let activityVC = UIActivityViewController(activityItems: [NSURL(string: "http://intro.dpgeek.cn")!], applicationActivities: activities)
        presentViewController(activityVC, animated: true, completion: nil)
    }
    func createHeader(){
        self.header = headerView(frame: commonVariable.HEADERPOSITION, leftBtnString: "< 返回", title: "开发者", rightBtnString: "分享")
        header?.delegate = self
        self.view.addSubview(self.header!)
    }
    func backAction(sender:UIButton){
        self.view.endEditing(true)
        self.dismissViewControllerAnimated(true) { () -> Void in
        }
    }
    func clickLeftBtn() {
        self.dismissViewControllerAnimated(true) { () -> Void in
            
        }
    }
    func clickRightBtn() {
        
    }
}